<!--
 * @Author: 曹捷
 * @Date: 2020-04-20 14:53:21
 * @LastEditors: 曹捷
 * @LastEditTime: 2021-05-21 15:04:03
 * @Description: 客户
 -->
<template>
  <el-select @change="choiceCus" filterable placeholder="请选择客户" v-model="cValue">
    <el-option :key="item.customerId" :label="item.customerName" :value="item.customerId" v-for="item in custList">
    </el-option>
  </el-select>
</template>
 
<script>
export default {
  props: {
    value: {
      type: [Number, String]
    },
    userName: {
      type: String
    }
  },
  data () {
    return {
      cValue: this.value,
      custList: []
    }
  },
  watch: {
    value () {
      this.cValue = this.value
    }
  },
  methods: {
    choiceCus (item) {
      this.$emit('input', item)
      let info = this.custList.find(ele => ele.customerId == item)
      this.$emit('update:userName', info.customerName)
    },
    initList () {
      this.$http.getAllCustomer().then(res => {
        this.custList = res
      })
    }
  },
  mounted () {
    this.initList()
  }
}
</script>
 
<style>
</style>
